Skip to content

获取机器码 - GetMachineCode

函数简介

获取本机的机器码,用于网站后台验证。

接口名称

GetMachineCode

DLL调用

long GetMachineCode(long ola);

参数说明

参数名类型说明
ola长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
string val = ola.GetMachineCode();
csharp
using OLAPlug;

var ola = new OLAPlugServer();
string val = ola.GetMachineCode();
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
val = ola.GetMachineCode()
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
String val = ola.GetMachineCode();
cpp
var ola = com("OlaPlug.OlaSoft")
var val = ola.GetMachineCode()
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
val = ola.GetMachineCode()
text
.局部变量 ola, OLAPlug
ola.创建 ()
val = ola.GetMachineCode()
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var val = ola.GetMachineCode();
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
文本型 val = ola.GetMachineCode()
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
string val = ola.GetMachineCode();

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long valPtr = GetMachineCode(instance);
if (valPtr != 0) {
    char val[512] = {0};
    GetStringFromPtr(valPtr, val, sizeof(val));
    FreeStringPtr(valPtr);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();

long instance = CreateCOLAPlugInterFace();
long valPtr = GetMachineCode(instance);
if (valPtr != 0) {
    StringBuilder val = new StringBuilder(GetStringSize(valPtr) + 1);
    GetStringFromPtr(valPtr, val, val.Capacity);
    FreeStringPtr(valPtr);
    string valStr = val.ToString();
}
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
valPtr = GetMachineCode(instance)
if valPtr:
    buf = create_string_buffer(512)
    ola.GetStringFromPtr(valPtr, buf, 512)
    ola.FreeStringPtr(valPtr)
    val = buf.value.decode("utf-8")

返回值

字符串:本机的机器码,调用进程无管理员权限时返回空串。

注意事项

  • DLL调用返回字符串指针地址,需要调用 FreeStringPtr 接口释放内存。
  • 调用进程必须有管理员权限,否则返回空串。
  • 机器码包含硬盘、显卡、网卡等硬件信息,重装系统不会改变此值。
  • 插拔任何USB设备(U盘、U盾、USB移动硬盘、USB键鼠等),以及安装任何网卡驱动程序(开启或关闭无线网卡等)都会导致机器码改变。